package com.ruoyi.boat.controller;

import java.util.List;

import com.ruoyi.boat.aop.AvoidDuplicate;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.boat.domain.AisData;
import com.ruoyi.boat.service.IAisDataService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * AIS数据Controller
 *
 * @author ruoyi
 * @date 2023-08-09
 */
@Controller
@RequestMapping("/boat/aisData")
public class AisDataController extends BaseController {
    private String prefix = "boat/aisData";

    @Autowired
    private IAisDataService aisDataService;

    @RequiresPermissions("boat:aisData:view")
    @GetMapping()
    public String aisData() {
        return prefix + "/aisData";
    }

    /**
     * 查询AIS数据列表
     */
    @RequiresPermissions("boat:aisData:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AisData aisData) {
        startPage();
        List<AisData> list = aisDataService.selectAisDataList(aisData);
        return getDataTable(list);
    }

    /**
     * 导出AIS数据列表
     */
    @RequiresPermissions("boat:aisData:export")
    @Log(title = "AIS数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @AvoidDuplicate
    @ResponseBody
    public AjaxResult export(AisData aisData) {
        List<AisData> list = aisDataService.selectAisDataList(aisData);
        ExcelUtil<AisData> util = new ExcelUtil<AisData>(AisData.class);
        return util.exportExcel(list, "AIS数据");
    }

    /**
     * 新增AIS数据
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存AIS数据
     */
    @RequiresPermissions("boat:aisData:add")
    @Log(title = "AIS数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AisData aisData) {
        return toAjax(aisDataService.insertAisData(aisData));
    }

    /**
     * 修改AIS数据
     */
    @RequiresPermissions("boat:aisData:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        AisData aisData = aisDataService.selectAisDataById(id);
        mmap.put("aisData", aisData);
        return prefix + "/edit";
    }

    /**
     * 修改保存AIS数据
     */
    @RequiresPermissions("boat:aisData:edit")
    @Log(title = "AIS数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AisData aisData) {
        return toAjax(aisDataService.updateAisData(aisData));
    }

    /**
     * 删除AIS数据
     */
    @RequiresPermissions("boat:aisData:remove")
    @Log(title = "AIS数据", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(aisDataService.deleteAisDataByIds(ids));
    }
}
